package org.gikolet.ch2.android.widget;

import java.util.List;

import org.gikolet.ch2.data.Res;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.Paint.FontMetrics;
import android.text.Layout;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.MeasureSpec;

public class ResesView extends View {

	private List<Res> reses;

	private TextPaint textPaint = new TextPaint();

	public ResesView(Context context) {
		super(context);
	}

	public ResesView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public ResesView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	@Override
	protected void onDraw(Canvas canvas) {
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		int width = MeasureSpec.getSize(widthMeasureSpec);
		/*
		 * if (layout != null) { setMeasuredDimension(layout.getWidth(),
		 * layout.getHeight());
		 *
		 * } else { super.onMeasure(widthMeasureSpec, heightMeasureSpec); }
		 */
	}

	private class DrawBlock {
		int x;
		int y;
		int width;
		int height;

		List<DrawInline> inlines;

		public Rect getPrefSize(int pw, int ph) {

			int lineX = 0;
			int height = 0;

			for (int i = 0; i < inlines.size(); i++) {

				DrawInline inline = inlines.get(i);

				int lineBreakPoint;
				int prevCurrentIndex = 0;
				int currentIndex = 0;// 現在、原文の何文字目まで改行が入るか確認したかを保持する

				do {
					lineBreakPoint = inline.paint.breakText(inline.text,
							currentIndex, inline.text.length(), true, pw
									- lineX, null);

					if (lineBreakPoint != 0) {
						height += inline.paint.getTextSize();
						prevCurrentIndex = currentIndex;
						currentIndex += lineBreakPoint;

					} else {
						lineX = inline.paint.getTextWidths(inline.text,
								prevCurrentIndex, inline.text.length(), null);
					}

				} while (lineBreakPoint != 0);
			}
			return null;
		}
	}

	private class DrawInline {
		String text;

		TextPaint paint;
		int color;

		int x;

	}
}
